package com.xy.designPatterns.observer;

import java.util.ArrayList;
import java.util.List;

public class Order implements OrderStatusSubject {

    private List<OrderStatusObserver> observers = new ArrayList<>();

    private OrderStatus status;

    @Override
    public void registerObserver(OrderStatusObserver observer) {
        observers.add(observer);
    }

    @Override
    public void removeObserver(OrderStatusObserver observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObservers() {
        for (OrderStatusObserver observer : observers) {
            observer.update(this);
        }
    }

    public void setStatus(OrderStatus status) {
        this.status = status;
        notifyObservers();
    }

    public OrderStatus getStatus() {
        return this.status;
    }
}
